package com.erlinyou.im.web.config.swagger;  
  
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.google.common.base.Predicates;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.Tag;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableWebMvc  
@EnableSwagger2  
@Configuration  
public class APPApiConfig extends WebMvcConfigurationSupport{ 
	
	/**
	 * 
	 * @return
	 */
	@Bean  
    public Docket createRecordApi() {  
    	
    	ParameterBuilder tokenPar = new ParameterBuilder();  
        List<Parameter> pars = new ArrayList<Parameter>();  
        tokenPar.name("xAuthToken").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();  
        pars.add(tokenPar.build());  
    	
        return new Docket(DocumentationType.SWAGGER_2) 
        		.groupName("IM")
                .apiInfo(recordInfo("1"))
                .tags(new Tag("Chat", "聊天相关接口"),getTags())
                .select()
                
                .apis(RequestHandlerSelectors.withClassAnnotation(Controller.class)/*RequestHandlerSelectors.basePackage("com.erlinyou.*.web.controller")*/)  
                .paths(/*Predicates.or(
                		PathSelectors.ant("/es/**"),
                		PathSelectors.ant("/nd/**")
                		)*/
                		Predicates.or(
                				PathSelectors.regex("/im/.*"),
                				PathSelectors.regex("/move/.*"),
                				PathSelectors.regex("/u/.*"),PathSelectors.regex("/motion/.*"))
                		
        				)
                .build().globalOperationParameters(pars);  
    }
  
    private ApiInfo recordInfo(String v) {  
        return new ApiInfoBuilder()  
                .title("在线搜索")
                .description("在线搜索")
                .version(v)
                .contact(new Contact("zhaoj", "", "zhaoj@zorrogps.com"))
                .license("精彩旅图(北京)科技发展有限公司")
                .licenseUrl("http://www.erlinyou.com")
                .build();  
    }  
    
    private Tag[] getTags(){
    	Tag[] tags={
    			new Tag("User", "用户相关")
    	};
    	return tags;
    }
    
}  